package club.haomoon.boss.service.impl;

import club.haomoon.boss.service.IChannelOpService;
import club.haomoon.boss.validate.base.ChannelOpValidate;
import club.haomoon.boss.vo.base.ChannelOpVo;
import club.haomoon.core.util.ConfigUtil;
import club.haomoon.core.util.PropertyUtil;
import club.haomoon.core.util.StringUtils;
import org.springframework.stereotype.Service;

/**
 * -------------------------
 * @Description: 开放平台设置服务类
 * @Author: Wangjianwei
 * @Date: 2025/02/18 16:50
 * -------------------------
 */
@Service
public class ChannelOpServiceImpl implements IChannelOpService {

    /**
     * 开放平台设置详情
     * @return ChannelOpVo
     */
    @Override
    public ChannelOpVo getConfig() {
        String appId = ConfigUtil.get("open_platform", "app_id", "");
        String appSecret = ConfigUtil.get("open_platform", "app_secret", "");

        String env = PropertyUtil.get("cms.production");
        boolean envStatus = StringUtils.isNotNull(env) && env.equals("true");

        ChannelOpVo vo = new ChannelOpVo();
        vo.setAppId(envStatus ? "******" : appId);
        vo.setAppSecret(envStatus ? "******" : appSecret);
        return vo;
    }

    /**
     * 开放平台设置保存
     * @param opValidate 参数
     */
    @Override
    public void setConfig(ChannelOpValidate opValidate) {
        ConfigUtil.set("open_platform", "app_id", opValidate.getAppId());
        ConfigUtil.set("open_platform", "app_secret", opValidate.getAppSecret());
    }

}
